<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Killmail</title>
</head>

<?php

// get configuration
include "config.php";

// connect to database
$killboardDatabase = mysql_connect($serverAddress, $databaseUsername, $databasePassword);
mysql_select_db($databaseToUse,$killboardDatabase);

// register_globals support
if (isset($_GET['mail']))
{
	$mail = $_GET['mail'];
}
else
{
	$mail = "";
}

$sql = "SELECT * FROM `kb_kill` WHERE (`killID` = $mail)";
$result = mysql_query($sql);

$killMail = mysql_fetch_row($result);
$uncompressedData = $killMail[7];

$fixedMail = str_replace("<br>","\r\n", $uncompressedData);

if ($fixedMail == NULL)
{
	$sql = "SELECT `PlayerName` FROM `Player` WHERE (`PlayerID` = '$killMail[1]')";
	$queryResult = mysql_query($sql);
	$playerName = mysql_result($queryResult, 0, 0);
	
	$sql = "SELECT `CorpName` FROM `Corp` WHERE (`CorpID` = '$killMail[2]')";
	$queryResult = mysql_query($sql);
	$corpName = mysql_result($queryResult, 0 ,0);
	
	$sql = "SELECT `ShipName` FROM `Ship` WHERE (`ShipID` = '$killMail[3]')";
	$queryResult = mysql_query($sql);
	$shipName = mysql_result($queryResult, 0, 0);
	
	$sql = "SELECT `SystemName`, `SecStatus` FROM `System` WHERE (`SystemID` = '$killMail[4]')";
	$queryResult = mysql_query($sql);
	$systemName = mysql_result($queryResult, 0, 0);
	$systemSecurity = mysql_result($queryResult, 0, 1);
	
	$fixedMail .= str_replace("-", ".", $killMail[6]) . " " . $killMail[5] . "\r\n";
	$fixedMail .= "\r\n";
	$fixedMail .= "Victim: " . $playerName . "\r\n";
	$fixedMail .= "Alliance: NONE" . "\r\n";
	$fixedMail .= "Corp: " . $corpName . "\r\n";
	$fixedMail .= "Destroyed: " . $shipName . "\r\n";
	$fixedMail .= "System: " . $systemName . "\r\n";
	$fixedMail .= "Security: " . $systemSecurity . "\r\n";
	$fixedMail .= "\r\n";
	$fixedMail .= "Involved parties:" . "\r\n";
	$fixedMail .= "\r\n";
	
	$sql = "SELECT * FROM `Involved` WHERE (`KillID` = '$mail')";
	$involvedQueryResult = mysql_query($sql);
	while ($involvedDetails = mysql_fetch_array($involvedQueryResult))
	{
	
		$sql = "SELECT `PlayerName` FROM `Player` WHERE (`PlayerID` = '$involvedDetails[2]')";
		$queryResult = mysql_query($sql);
		$playerName = mysql_result($queryResult, 0, 0);
		
		if ($involvedDetails[6] == "1")
		{
			$playerName .= " (laid the final blow)";
		}
		
		$sql = "SELECT `CorpName` FROM `Corp` WHERE (`CorpID` = '$involvedDetails[3]')";
		$queryResult = mysql_query($sql);
		$corpName = mysql_result($queryResult, 0 ,0);
		
		$sql = "SELECT `ShipName` FROM `Ship` WHERE (`ShipID` = '$involvedDetails[4]')";
		$queryResult = mysql_query($sql);
		$shipName = mysql_result($queryResult, 0, 0);
	
		$sql = "SELECT `ItemName` FROM `Item` WHERE (`ItemID` = '$involvedDetails[5]')";
		$queryResult = mysql_query($sql);
		$weaponName = mysql_result($queryResult, 0, 0);
		
		$fixedMail .= "Name: " . $playerName . "\r\n";
		$fixedMail .= "Security: 0.0" . "\r\n";
		$fixedMail .= "Alliance: NONE" . "\r\n";
		$fixedMail .= "Corp: " . $corpName . "\r\n";
		$fixedMail .= "Ship: " . $shipName . "\r\n";
		$fixedMail .= "Weapon: " . $weaponName .  "\r\n";	
		$fixedMail .= "\r\n";	
	}
}


mysql_close($killboardDatabase);

?>

<form>
<textarea rows="30" cols="50">
<?php
echo ($fixedMail);
?>
</textarea>
<body>
</body>
</html>
